/*
 * @Author: lineCode 1145938682@qq.com
 * @Date: 2024-11-23 18:25:27
 * @LastEditors: lineCode 1145938682@qq.com
 * @LastEditTime: 2025-06-26 12:26:47
 * @FilePath: /backend/shorthand-modules/shorthand-modules-front/src/main/java/com/angus/modules/front/repository/FrontOperLogRepository.java
 */
package com.angus.modules.front.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.angus.api.front.domain.FrontOperLog;
import com.angus.modules.front.mapper.FrontOperLogMapper;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @author liyanan
 * @date 2024/10/19 12:58 PM
 * @description
 */
@Repository
public class FrontOperLogRepository extends ServiceImpl<FrontOperLogMapper, FrontOperLog> {
    public int insertOperlog(FrontOperLog operLog) {
        return baseMapper.insert(operLog);
    }

    public void cleanOperLog() {
        baseMapper.cleanOperLog();
    }

    public List<FrontOperLog> selectOperLogList(String operIp,
                                                String operName,
                                                String title,
                                                Integer businessType,
                                                Integer status,
                                                String beginTime,
                                                String endTime) {

        LambdaQueryWrapper<FrontOperLog> queryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.isNotBlank(operIp)){
            queryWrapper.like(FrontOperLog::getOperIp,operIp);
        }
        if (StringUtils.isNotBlank(operName)){
            queryWrapper.like(FrontOperLog::getOperName,operName);
        }
        if(StringUtils.isNotBlank(title)){
            queryWrapper.like(FrontOperLog::getTitle,title);
        }
        if(Objects.nonNull(businessType)){
            queryWrapper.eq(FrontOperLog::getBusinessType,businessType);
        }
        if(Objects.nonNull(status)){
            queryWrapper.eq(FrontOperLog::getStatus,status);
        }
        if(StringUtils.isNotBlank(beginTime)){
            queryWrapper.ge(FrontOperLog::getOperTime,beginTime);
        }
        if (StringUtils.isNotBlank(endTime)){
            queryWrapper.le(FrontOperLog::getOperTime,endTime);
        }

        queryWrapper.orderByDesc(FrontOperLog::getOperId);

        return baseMapper.selectList(queryWrapper);
    }

    public void deleteOperLogByIds(List<Long> operIds) {
        baseMapper.deleteBatchIds(operIds);
    }
}
